package com.domus.dreamMenu.servidor.bancodados;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public abstract class ConexaoBancoDados {

	protected static Connection conexao;

	protected ConexaoBancoDados(){
		if(ConexaoBancoDados.conexao == null)
			ConexaoBancoDados.inicializarConnection();
	}

	private static void inicializarConnection() {
		try {
			Class.forName("org.postgresql.Driver");
			conexao = DriverManager.getConnection("jdbc:postgresql://postgres.cin.ufpe.br/g081if683_eq01",
					"g081if683_eq01", "DomusMenu");

			Statement s = conexao.createStatement();
			s.execute("SET search_path TO dreamenu;");
			
			s.execute("VACUUM;");

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void fecharConexao() {
		try {
			if(ConexaoBancoDados.conexao != null)
				ConexaoBancoDados.conexao.close();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}	

}
